// src/directives/permissionDirective.js
import store from '@/store'

export default {
  inserted: function (el, binding, vnode) {
    const { value } = binding
    const buttonPermissions = store.getters.permissions
  // console.log(buttonPermissions,'buttonPermissions2--')

    if (value && value instanceof Array) {
      if (value.length > 0) {
        const permissionFlag = value

        const hasPermission = buttonPermissions.some(permission => {
          return permissionFlag.includes(permission)
        })

        if (!hasPermission) {
          el.parentNode && el.parentNode.removeChild(el)
        }
      }
    } else {
      throw new Error(`need permissions! Like v-permission="['add','del']"`)
    }
  }
}
